from pydantic import BaseModel, Field, ConfigDict
from pydantic.types import UUID4
from typing import Optional, List
from datetime import datetime

from app.models.broadcast_task import TriggerType, Priority, Speed, BroadcastTargetCategory, BroadcastContentCategory
from app.schemas.archivable import Archivable


# 共享属性
class BroadcastTaskBase(BaseModel):
    name: str = Field(..., description="任务名称")
    category: str = Field(..., description="播报分类")
    description: str = Field(..., description="任务简介")
    trigger_type: TriggerType = Field(..., description="触发类型")
    warning_time: Optional[datetime] = Field(None, description="定时预警时间")
    priority: Optional[Priority] = Field(None, description="优先级")
    monitor_data: Optional[str] = Field(None, description="监控数据")
    condition: Optional[str] = Field(None, description="判断条件")
    broadcast_target_category: BroadcastTargetCategory = Field(..., description="播报对象的分类")
    # broadcast_target_ids: List[str] = Field(..., description="播报对象用户ID列表")
    broadcast_target_ids: Optional[List[UUID4]] = Field(default=["79b026c4-8519-4c90-a4ff-c0b34b8cbfc5"], description="播报对象用户ID列表")
    broadcast_content_category: BroadcastContentCategory = Field(..., description="播报内容的分类")
    broadcast_content_ids: Optional[List[UUID4]] = Field(default=["544a49b9-6d36-47b6-aeb6-e615f6245bbb"], description="播报内容ID列表")
    broadcast_content: Optional[str] = Field(None, description="播报内容")
    speed: Speed = Field(..., description="语速")
    repeat_frequency: int = Field(..., description="重复频率")
    auto_read: bool = Field(..., description="自动朗读")


# 通过API创建时接收的属性
class BroadcastTaskCreate(BroadcastTaskBase):
    pass


# 通过API更新时接收的属性
class BroadcastTaskUpdate(BroadcastTaskBase):
    pass


# 数据库中存储的属性
class BroadcastTaskInDBBase(BroadcastTaskBase, Archivable):
    audio_url: Optional[str] = Field(None, description="音频文件URL")
    model_config = ConfigDict(from_attributes=True)

    id: UUID4


# 通过API返回的属性
class BroadcastTask(BroadcastTaskInDBBase):
    pass


# 数据库中存储的属性（额外）
class BroadcastTaskInDB(BroadcastTaskInDBBase):
    pass


# 播报对象（是否保留有待商榷）
# 共享属性
class BroadcastTargetBase(BaseModel):
    name: str = Field(..., description="播报对象名称")
    department: str = Field(..., description="所属部门")


# 通过API创建时接收的属性
class BroadcastTargetCreate(BroadcastTargetBase):
    pass


# 通过API更新时接收的属性
class BroadcastTargetUpdate(BroadcastTargetBase):
    pass


# 数据库中存储的属性
class BroadcastTargetInDBBase(BroadcastTargetBase, Archivable):
    model_config = ConfigDict(from_attributes=True)

    id: UUID4


# 通过API返回的属性
class BroadcastTarget(BroadcastTaskInDBBase):
    pass


# 数据库中存储的属性（额外）
class BroadcastTargetInDB(BroadcastTaskInDBBase):
    pass
